﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Windows.Forms;


namespace StringFormatting
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine(StringToHexadecimal("Hi!"));


            //Write a program, which prints a 4 column table for each integer from 5 to 25. Columns should contain:
            //The number (lined up on the right in a 5-digit space).
            //The square of the number (lined up on the left in a 6-digit space).
            //The square root of the number (with a 4-digit precision, in a 10-digit space, with leading zeros at the start).
            //The natural logarithm of the number (as precise as possible).

            //for (int i = 5; i < 25; i++)
            //{
            //    Console.Write("{0,5} ",i);
            //    Console.Write("{0,-6:0.####} ", Math.Sqrt(i));
            //    Console.Write("{0,-10:0.0000} ", Math.Sqrt(i));
            //    Console.WriteLine("{0} ", Math.Log(i,Math.E));
            //    Console.WriteLine();
            //}


            //Fraction frac = new Fraction(4, 3);
            //Console.WriteLine("{0:R}",frac);


            //Write a program that expects as input a date in any of the formats "dd.mm.yyyy", "dd/mm/yyyy", "dd.mm.yy" or "dd/mm/yy", parses the input and if the input is one of the formats, prints the date in the following format: day=DD, month=MM, year=YYYY.

            //Console.WriteLine("Enter a date:");
            //DateTime myDate = DateTime.Parse(Console.ReadLine());
            //Console.WriteLine("day={0:dd},month={0:MM},year={0:yyyy}",myDate);


            //Write a program that reads a real number from the console and then prints it in a currency format specific for the countries : Austria, Bulgaria, Israel, Mongolia, Taiwan and Japan. Answer the question: Why are question marks printed in some of the formats?

            //Console.WriteLine("Enter a value:");
            //double value = double.Parse(Console.ReadLine());
            //ShowAmmount(value, new CultureInfo("bg-BG"));
            //ShowAmmount(value, new CultureInfo("de-AT"));
            //ShowAmmount(value, new CultureInfo("he-IL"));
            //ShowAmmount(value, new CultureInfo("mn-MN"));
            //ShowAmmount(value, new CultureInfo("zh-TW"));
            //ShowAmmount(value, new CultureInfo("ja-JP"));


            //Write a program that reads a string input from the console and tries to convert it to a number, using the formats "XXX XXX XXX.YY", "XXX XXX XXX,YY", "XXXXXXXXX,YYY", "XXXXXXXXX.YY". Use the  Double.Parse() method and the CultureInfo class. You may need first to clear the whitespace characters and replace the comma floating-point separator "," with a dot ".".
            Console.WriteLine(StringToNumber("1 24  ,567"));

        }

        static string StringToNumber(string input)
        {
            StringBuilder corrString = new StringBuilder();
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] == ',')
                {
                    corrString.Append('.');
                }
                else
                {
                    if (input[i] != ' ')
                    {
                        corrString.Append(input[i]);
                    }
                }
            }
            try
            {
                double.Parse(corrString.ToString());
                return corrString.ToString();
            }
            catch (Exception)
            {
                return "Incorrect.";
            }

        }

        static void ShowAmmount(double ammount, CultureInfo culture)
        {
            string message =
               String.Format(culture, "Ammount: {0:C}", ammount);

            String caption = culture.EnglishName;
            MessageBox.Show(message, caption);
        }



        public static string StringToHexadecimal(string str)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            StringBuilder builder = new StringBuilder();
            foreach (var bytee in bytes)
            {
                builder.Append(string.Format(@"\x{0:X}", bytee));
            }
            return builder.ToString();
        }
    }
}
